package io.renren.modules.user.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import io.renren.modules.user.entity.TPeopleEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.user.entity.TPeopleOutEntity;
import io.renren.modules.user.service.TPeopleOutService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 人员退出表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-08 09:38:01
 */
@RestController
@RequestMapping("/tpeopleout")
public class TPeopleOutController {
    @Autowired
    private TPeopleOutService tPeopleOutService;

    /**
     * 列表
     */
    @RequestMapping("/list")
  //  @RequiresPermissions("user:tpeopleout:list")
    public R list(@RequestBody TPeopleOutEntity tPeopleOutEntity){
        Map<String, Object> params=new HashMap<>();
        params.put("page",tPeopleOutEntity.getPage());
        params.put("page",tPeopleOutEntity.getLimit());
        /*params.put("deptId",tPeopleOutEntity.getDeptId());*/
        PageUtils page = tPeopleOutService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:tpeopleout:info")
    public R info(@PathVariable("id") Integer id){
		TPeopleOutEntity tPeopleOut = tPeopleOutService.getById(id);

        return R.ok().put("tPeopleOut", tPeopleOut);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:tpeopleout:save")
    public R save(@RequestBody TPeopleOutEntity tPeopleOut){
		tPeopleOutService.save(tPeopleOut);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:tpeopleout:update")
    public R update(@RequestBody TPeopleOutEntity tPeopleOut){
		tPeopleOutService.updateById(tPeopleOut);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:tpeopleout:delete")
    public R delete(@RequestBody Integer[] ids){
		tPeopleOutService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 人员退出列表
     */
    @RequestMapping("/listPeopleOut")
    //  @RequiresPermissions("user:tpeopleout:list")
    public R listPeopleOut(@RequestBody TPeopleOutEntity tPeopleOutEntity){
        Map<String, Object> params=new HashMap<>();
        params.put("page",tPeopleOutEntity.getPage());
        params.put("limit",tPeopleOutEntity.getLimit());
        params.put("deptId",tPeopleOutEntity.getDeptId());
        params.put("peopleType",tPeopleOutEntity.getPeopleType());
        params.put("likeName",tPeopleOutEntity.getLikeName());
        params.put("classes",tPeopleOutEntity.getClasses());
        params.put("title",tPeopleOutEntity.getTitle());
        params.put("num",tPeopleOutEntity.getNum());
        params.put("year",tPeopleOutEntity.getYear());
        params.put("zdeptId",tPeopleOutEntity.getZdeptId());
        PageUtils page = tPeopleOutService.listPeopleOut(params);
        return R.ok().put("page", page);
    }

    /**
     * 返聘
     */
    @RequestMapping("/rehireAfterRetirement")
    //@RequiresPermissions("generator:tpeopleout:rehireAfterRetirement")
    public R rehireAfterRetirement(@RequestBody TPeopleOutEntity tPeopleOut){
        tPeopleOutService.rehireAfterRetirement(tPeopleOut);
        tPeopleOutService.rehireAfterRetirements(tPeopleOut);
        return R.ok();
    }

}
